package com.xiaoma.lib.store

/**
 * author: liangjingbo
 * date: 2022/6/17
 * describe:
 */
internal interface IStore {
    /**
     * 基础类型的保存
     *
     * @param key   key
     * @param value value
     * @return is operation success
     */
    fun put(key: String, value: Any): Boolean

    /**
     * 基础类型的获取
     *
     * @param key          key
     * @param defaultValue defaultValue
     * @return the save value or defaultValue for none
     */
    operator fun <T> get(key: String, defaultValue: T): T

    /**
     * 非泛型对象的保存
     *
     * @param key    key
     * @param object Non-generic object, object's fields also couldn't be generic
     * @return is operation success
     */
    fun <T> putObject(key: String, `object`: T): Boolean

    /**
     * 非泛型对象的获取
     *
     * @param key    key
     * @param tClass Non-generic object class
     * @param <T>    object type
     * @return the save object or null for none
    </T> */
    fun <T> getObject(key: String, tClass: Class<T>): T?

    /**
     * 集合的保存
     *
     * @param key  key
     * @param list list object
     * @return is operation success
     */
    fun <T> putList(key: String, list: List<T>?): Boolean

    /**
     * 集合的获取
     *
     * @param key    key
     * @param tClass list object class
     * @param <T>    object type
     * @return the save list or null for none
    </T> */
    fun <T> getList(key: String, tClass: Class<Array<T>>): List<T>?

    /**
     * 判断是否包含某个key
     *
     * @param key key
     * @return is contains the key
     */
    operator fun contains(key: String): Boolean

    /**
     * 移除key对应的value
     *
     * @param key key
     * @return is operation success
     */
    fun remove(key: String): Boolean

    /**
     * 清空所有数据
     *
     * @return is operation success
     */
    fun clear(): Boolean

}
